package StudyCode.summary.mycollection;

import java.lang.reflect.Array;
import java.util.Collection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertsATypedCollectionToATypedArray {
	public static void main(String[] argv) {
		Class type = String.class;
		Collection collection = java.util.Arrays.asList("科技与人文",
				"www.tah1986.com");
		System.out.println(java.util.Arrays.toString(toArray(type,
				collection)));
	}

	@SuppressWarnings("unchecked")
	public static <T> T[] toArray(Class<T> type, Collection<T> collection) {
		return collection.toArray((T[]) Array.newInstance(type,
				collection.size()));
	}
}
